/**
{
"style":{
"navigationBarTitleText":"登录",
"navigationStyle": "custom",
}
}
*/
<template>
	<view class="page-bg">
		<u-navbar title="登录" leftIcon="home" @leftClick="leftClick"></u-navbar>
		<view class="con">
			<view class="image">
				<!-- <image src="/static/image/logo.png" mode=""></image> -->
			</view>

			<view class="title">欢迎登录新君涛验车</view>

			<u-button class="custom-style" color="#0F956E" text="手机号快捷登录" open-type="getPhoneNumber"
				@getphonenumber="getphonenumber" :customStyle="{
					width: '636rpx',
					height: '80rpx',
					margin: '178rpx auto 0'
				}" v-if="isAgree"></u-button>


			<u-button class="custom-style" color="#0F956E" text="手机号快捷登录" :customStyle="{
					width: '636rpx',
					height: '80rpx',
					margin: '178rpx auto 0'
				}" v-else @click="onLogin"></u-button>
			<!-- <view class="btn" v-else @click="onLogin">
				手机号快捷登录
			</view> -->
			<view class="xiexi-login flex-all-c" @click="isAgree = !isAgree">
				<view class="check flex-all-c">
					<u-icon name="checkmark" color="#0F956E" size="14" v-if="isAgree"></u-icon>
				</view>
				我已阅读并同意
				<text @click.stop="jumpXX(1)">《用户服务协议》</text>
				<text @click.stop="jumpXX(2)">《隐私协议》</text>
			</view>
			<!-- <view class="hint1 hint-login" @click="jumpLogin" v-if="envVersion != 'release'">账号密码登录</view> -->
		</view>
	</view>
</template>

<script>
	// import {
	// 	codeLogin,
	// 	getCartCount,
	// 	getUserInfo
	// } from '@/apis/home.js';
	export default {
		data() {
			return {
				isAgree: false,
				type: '',
				envVersion: ''
			};
		},
		onLoad(options) {
			this.type = options.type
			this.envVersion = uni.getStorageSync('envVersion');
		},
		methods: {
			leftClick() {
				uni.switchTab({
					url: '/pages/index/index'
				});
			},
			getphonenumber(e) {
				if (e.detail.errMsg == "getPhoneNumber:ok") {
					const _this = this
					uni.login({
						provider: 'weixin',
						async success(res) {
							let invite_id = ''
							if (uni.getStorageSync('fid')) {
								invite_id = uni.getStorageSync('fid');
							};
							let res2 = await $post("/index/wxtel", {
								code: res.code,
								encryptedData: e.detail.encryptedData,
								iv: e.detail.iv,
								// vid: _this.currentxqInfo.id,
								invite_id: invite_id,
							})

							uni.setStorageSync('token', res2.token)

							// const res3 = await getUserInfo()
							const res3 = await $post("/user/get_user")
							uni.setStorageSync('userId', res3.info.id)

							if (invite_id && invite_id != res3.info.id) {
								const res4 = await $post("/index/binding", {
									fid: invite_id
								})
								console.log(res4,'123123123123')
							}

							try {
								uni.navigateBack({
									delta: 1
								});
							} catch (e) {
								uni.switchTab({
									url: "/pages/index/index"
								})
							}
							return
							if (_this.type == 1) {
								const fromPage = uni.getStorageSync('fromPage')
								if (fromPage == 'my') {
									uni.switchTab({
										url: "/pages/my/my"
									})
								} else if (fromPage == 'card') {
									uni.switchTab({
										url: "/pages/card/card"
									})
								} else {
									uni.navigateBack({
										delta: 1
									});
								}
								uni.removeStorageSync('fromPage')
							} else {
								uni.switchTab({
									url: "/pages/index/index"
								})
							}

						}
					});
				}
			},
			jumpLogin() {
				uni.redirectTo({
					url: '/pages/account/login?type=' + this.type
				});
			},
			onLogin() {
				if (!this.isAgree) {
					uni.showToast({
						icon: 'none',
						title: '请阅读并同意协议'
					})
				}
			},
			jumpXX(type) {
				uni.navigateTo({
					url: '/pages/login/xieyi?type=' + type
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	.con {
		width: 100%;
		height: 100vh;
		// padding-top: 176rpx;

		.image {
			width: 100%;
			text-align: center;
			padding-top: 250rpx;

			image {
				width: 158rpx;
				height: 68rpx;
			}
		}

		.title {
			font-family: PingFang SC, PingFang SC;
			font-weight: 800;
			font-size: 34rpx;
			color: #333333;
			width: 100%;
			text-align: center;
			padding-top: 74rpx;
		}
	}

	.btn {
		width: 636rpx;
		height: 80rpx;
		margin: 178rpx auto 0;
		background-color: #0F956E;
		border-radius: 8rpx;
		color: #fff;
		line-height: 80rpx;
		text-align: center;
		font-size: 28rpx;
	}
</style>